package com.white.androidstudy;

import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.white.androidstudy.widget.PagerSlidingTabStrip;

public class WidgetShowActivity extends AppCompatActivity
{

    PagerSlidingTabStrip slid;
    ViewPager pager;

    String[] title = {"TAB1", "ATAB2", "TAB3TAB3", "TAB4", "ASTAB5", "TAB6", "TAB6", "TAB6", "TAB6", "TAB6", "TAB6", "TAB6"};

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_widget_show);
        slid = (PagerSlidingTabStrip) findViewById(R.id.slid);
        pager = (ViewPager) findViewById(R.id.pager);
        pager.setAdapter(new adapter());
        slid.setViewPager(pager);
    }

    class adapter extends PagerAdapter
    {

        @Override
        public CharSequence getPageTitle(int position)
        {
            return title[position];
        }

        @Override
        public int getCount()
        {
            return title.length;
        }

        @Override
        public boolean isViewFromObject(View view, Object object)
        {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position)
        {
            TextView tv = new TextView(WidgetShowActivity.this);
            LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT);
            tv.setLayoutParams(p);
            tv.setText(title[position]);
            container.addView(tv);
//            View v = View.inflate(WidgetShowActivity.this, R.layout.item_function, null);
//            container.addView(v);
            return tv;
        }


        @Override
        public void destroyItem(ViewGroup container, int position, Object object)
        {
            container.removeView((View) object);
        }
    }
}
